#pragma once
#include <iostream>
#include <string>
#include <mysql/mysql.h>

#include "../comm/log.hpp"

using namespace ns_log;

MYSQL *connect_db()
{
    MYSQL *conn = mysql_init(nullptr);
    if (conn == nullptr)
    {
        LOG(ERROR)<< "mysql_init() failed\n";
        return nullptr;
    }
    if (mysql_real_connect(conn, "127.0.0.1", "oj_client", "123456", "oj", 3306, nullptr, 0) == nullptr)
    {
        LOG(ERROR)<< "mysql_real_connect() failed\n";
        mysql_close(conn);
        return nullptr;
    }
    // 设置字符集
    mysql_set_character_set(conn, "utf8");
    return conn;
}